package com.ocom.payhandle.mq.business.saveorder.impl;


import com.ocom.common.utils.ThreadTaskUtils;
import com.ocom.payhandle.feign.MqSimpleFeign;
import com.ocom.payhandle.feign.UgcapiFeign;
import com.ocom.payhandle.feign.XfRecordFeign;
import com.ocom.payhandle.mq.business.saveorder.SaveOrderProductService;
import com.ocom.payhandle.mq.utils.SyncSaveOrderProductUitl;
import com.ocom.payhandle.runable.OrderRunnableTask;
import com.ocom.payhandle.service.*;
import com.ocom.payhandle.vo.MqSaveOrderVo;
import com.ocom.redis.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class SaveOrderProductServiceImpl implements SaveOrderProductService {


	@Autowired
	private SyncSaveOrderProductUitl syncSaveOrderProductUitl;

	@Autowired
	private XfRecordProcessService xfRecordProcessService;

	@Autowired
	private XfRecordProcessExxxService xfRecordProcessExxxService;

	@Autowired
	private XfGoodsListProcessService xfGoodsListProcessService;

	@Autowired
	private XfRecordFeign xfRecordFeign;

	@Autowired
	private XfMerchPayInfoService xfMerchPayInfoService;


	@Autowired
	private UgcapiFeign ugcapiFeign;

	@Autowired
	AbnormalService abnormalService;

	@Autowired
	private XfAccountTypeService xfAccountTypeService;

	@Autowired
	private CompanyConfigService companyConfigService;

	@Resource
	private RedisUtil redisUtil;

	@Autowired
	private MqSimpleFeign mqSimpleFeign;

	/**
	 * 更改门禁权限
	 */
//	@Transactional
	public void saveOrder(String msg) {
//		log.info("异步保存订单-初始化账号开始【{}】",msg);
		//消息队列调用保存订单  优先级越高越先执行完

//		Random random = new Random();
//		int randomNumber = random.nextInt(11);
		syncSaveOrderProductUitl.syncSaveOrder(msg,5);

	}

	/**
	 * 更改门禁权限
	 */
//	@Transactional
	public void saveOrder(String msg ,Integer priority) {
//		log.info("异步保存订单-初始化账号开始【{}】",msg);
		//消息队列调用保存订单  优先级越高越先执行完
		syncSaveOrderProductUitl.syncSaveOrder(msg,priority);

//		log.info("异步保存订单-初始化账号完成【{}】",msg);
	}

	public void saveOrder(MqSaveOrderVo mqSaveOrderVo) {
//		log.info("异步保存订单-初始化账号开始【{}】",msg);
		//消息队列调用保存订单  优先级越高越先执行完
//		syncSaveOrderProductUitl.syncSaveOrder(msg,priority);
		ThreadTaskUtils.run(new OrderRunnableTask(
				xfRecordProcessExxxService,
				xfGoodsListProcessService,
				xfRecordFeign,
				xfMerchPayInfoService,
				ugcapiFeign,
				abnormalService,
				xfAccountTypeService,
				companyConfigService,
				redisUtil,
				mqSimpleFeign,
				log,
				mqSaveOrderVo
		));
//		log.info("异步线程池保存订单-提交线程池订单完成【{}】",mqSaveOrderVo);
	}





}
